package com.example.api.controller.admin;


import com.example.api.query.BookQuery;
import com.example.api.service.BookService;
import com.example.api.utils.PageResult;
import com.example.api.utils.Result;
import com.example.api.vo.BookListVO;
import com.example.api.vo.BookVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

@RestController("adminBookController")
@RequestMapping("/admin/book")
@Api(tags = "订单管理接口")
public class BookController {

    @Resource
    private BookService bookService;


    @GetMapping
    @ApiOperation("订单搜索")
    public Result<List<BookListVO>> list(BookQuery bookQuery) {
        PageResult<BookListVO> page = bookService.find(bookQuery);
        return Result.ok("成功",page.getList(),page.getTotal());
    }

    /**
     * 更加订单编号查询详情信息
     * @param num
     * @return
     */
    @GetMapping("/{num}")
    public Result<BookVO> findByNum(@PathVariable String num) {
        BookVO bookVO = bookService.findByNum(num);
        return Result.ok("成功",bookVO);
    }

    @PutMapping("/{num}/receive")
    public Result<String> receive(@PathVariable String num) {
        bookService.receive(num);
        return Result.ok("成功");
    }

    @PutMapping("/{num}/reject")
    public Result<String> reject(@PathVariable String num,String reason) {
        bookService.reject(num,reason);
        return Result.ok("成功");
    }

    @PutMapping("/{num}/delivery")
    public Result<String> delivery(@PathVariable String num) {
        bookService.delivery(num);
        return Result.ok("派送中...");
    }

    @PutMapping("/{num}/complete")
    public Result<String> complete(@PathVariable String num) {
        bookService.complete(num);
        return Result.ok("订单完成");
    }
}